function [ A, B ] = firstconstraintgroup(P,x,N,eps1)
%FIRSTCONSTRAINTGROUP Summary of this function goes here
%   Detailed explanation goes here
A=zeros(2*(N-1)+2*N,N*4);
B=zeros(1,2*(N-1)+2*N);

vars = zeros(N,2);

 for l=1:N-1
    A(2*l-1,l) = 1;
    A(2*l-1,l+1) = -1;
    A(2*l,l) = -1;    
    A(2*l,l+1) = 1;
    
    A(2*l-1,l+N) = x(1,l+1);
    A(2*l-1,l+N+1) = -x(1,l+1);
    A(2*l,l+N) = -x(1,l+1);    
    A(2*l,l+N+1) = x(1,l+1);
    
    B(2*l-1) = eps1 -polyval(P(:,l),x(1,l+1))+polyval(P(:,l+1),x(1,l+1));
    B(2*l) = eps1 +polyval(P(:,l),x(1,l+1))-polyval(P(:,l+1),x(1,l+1));
 end

 shift = 2*(N-1);
 for l=1:N-1
    
    A(shift+2*l-1,l+N) = 1;
    A(shift+2*l-1,l+N+1) = -1;
    A(shift+2*l,l+N) = -1;    
    A(shift+2*l,l+N+1) = 1;
    
    B(shift+2*l-1) = eps1 -polyval(polyder(P(:,l)),x(1,l+1))+polyval(polyder(P(:,l+1)),x(1,l+1));
    B(shift+2*l) = eps1 +polyval(polyder(P(:,l)),x(1,l+1))-polyval(polyder(P(:,l+1)),x(1,l+1));
 end
  shift = 4*(N-1);
 for l=1:N
     A(shift+2*l-1,l) = 1;
     A(shift+2*l-1,2*N+l) = -1;
     B(shift+2*l-1) = 0;
     
     A(shift+2*l,l) = -1;
     A(shift+2*l,2*N+l) = -1;
     B(shift+2*l) = 0;
 end
  shift = 2*(N-1)+2*N;
 for l=1:N
     A(shift+2*l-1,l) = 1;
     A(shift+2*l-1,3*N+l) = -1;
     B(shift+2*l-1) = 0;
     
     A(shift+2*l,l) = -1;
     A(shift+2*l,3*N+l) = -1;
     B(shift+2*l) = 0;
 end

end

